package com.powerunion.datacollection.service;

import java.util.List;

import net.sf.json.JSONArray;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.powerunion.datacollection.common.SystemException;
import com.powerunion.datacollection.dao.DaoFactory;
import com.powerunion.datacollection.dao.ViewDataDao;
import com.powerunion.util.log.LogHelper;

public class ViewDataManager {
	private static Logger logger = LogHelper.getInstance().getLogger(
			ViewDataManager.class);
	private ViewDataDao dao = null;

	public ViewDataManager() {
		super();
		this.dao = (ViewDataDao) DaoFactory.getInstance().getDao(
				ViewDataDao.class);
	}
	
	public String getViewDataByUser(String userCode) throws Exception {
		// 参数为空
		if (StringUtils.isEmpty(userCode)) {
			String[] args = { "userCode" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter userCode NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		List cts = this.dao.getViewDataByUser(userCode);
		JSONArray jsonArr = JSONArray.fromObject(cts);
		String result = "{results:"+jsonArr+"}";
		return result;
	}

	
	
}
